<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');

class Article extends CI_Controller {
    private $rear = '';
    private $allchild = array();
    private $per_page = 5;
    private $total_rows = 6;
    function  __construct(){
        parent::__construct();        
    }
       
    function index($category_alias='',$article_alias=''){
        $category = '';
        //$this->db->cache_on();
        //$this->output->cache(600);
        $category =  $this->Home_model->get_one('categories',array('alias'=>$category_alias,'show'=>1));
        if(!$category){
            $category ->content = '<p>Danh mục này không tồn tại</p>';
        }else{
            if(!empty($article_alias)){
                $article = $this->Home_model->get_one('content',array('catid'=>$category->id,'alias'=>$article_alias));                
                $category ->content = $this->load->view('article/detail',array('category'=>$category,'article'=>$article),true);
            }else{
                $article =  $this->Home_model->get_data('content',array('catid'=>$category->id)); 
                $this->total_rows = $this->Home_model->get_number('content',array('catid'=>$category->id));
                $this->phantrang();
                $category ->content =$this->load->view('article/category',array('category'=>$category,'article'=>$article),true);
            }
        }
        //$this->db->cache_off();         
        $dt = $this->template->render($category);  
        $this->load->view('default/viewfull',$dt);
        
    }    
    function phantrang(){
        $this->load->library('pagination');
        $config['base_url'] = base_url().$this->uri->segment(1).'/'.$this->uri->segment(2).'/';
        $config['total_rows'] = $this->total_rows;
        $config['per_page'] = $this->per_page;
        $config['uri_segment'] = 1;
        $config['num_links'] = 12;
        $this->pagination->initialize($config);
    }
}